package logic;

import static org.junit.Assert.*;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.junit.Test;

import affd.logic.Extractor;
import affd.logic.NameReplacementFI;
import affd.logic.Sentence;
import affd.logic.Token;

public class NameReplacementFITest {

	@Test
	public void testReplaceAsAddress() {

		ArrayList<Sentence> sentences = new TestData().getTestData();
		String original = "";

		for(Sentence s : sentences) {
			if (s.toString().trim().startsWith("Teron osoite")) {
				original = s.toString();
			}
		}

		Extractor extractor = new Extractor();
		HashMap<String, ArrayList<Token>> hm = null;
		
		try {
			hm = extractor.extractPossibleNames(sentences);
		} catch (IOException e) {
			fail("IOException");
		}
			
		String[] POSSIBLE_ADDRESSES = {"katu", "tie", "kuja", "polku", "kaari", "rinne"};
			
		NameReplacementFI f = new NameReplacementFI();
			
		boolean isa = false;
		if (hm != null) {
			for (String s : hm.keySet()) {
				
				for (String address : POSSIBLE_ADDRESSES) {
					if (s.trim().endsWith(address)) {
						isa = true;
						break;
					}
				}
				if (isa) {
					f.replaceAsAddress(s, hm.get(s));
					isa = false;
				}
			}			
		}
			
		String after = "";
			
		for(Sentence s : sentences) {
			if (s.toString().trim().startsWith("Teron osoite")) {
				after = s.toString();
			}
		}
		assertEquals(original.replace("Testikatu 2 C", "Paikka A"), after);
	}
}
